package de.hska.reka.websockets.client;

import org.springframework.stereotype.Component;
import org.xlightweb.IWebSocketConnection;
import org.xlightweb.client.HttpClient;

import de.hska.reka.websockets.AbstractServiceExporter;

@Component
public class WebSocketClientServiceExporter extends AbstractServiceExporter {

	public void afterPropertiesSet() throws Exception {
		this.webSocketRawHandler
				.setControllerMethodMapPrototype(this.controllerMethodMap);
		this.webSocketRawHandler
				.setInvocationHandler(this.oneToManyInvocationHandler);
	}

	@Override
	public void initialized() {
		try {
			HttpClient client = new HttpClient();
			// supress warning, because var is never be used in this context again directly
			@SuppressWarnings("unused")
			IWebSocketConnection connection = client.openWebSocketConnection(
					this.getServiceUrl(), this.webSocketRawHandler);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
